home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1104 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.4 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: "Nathan Myers <ncm@cantrip.org>" <ncm@cantrip.org>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: exceptions in std lib
  5. Date: 16 Apr 1996 06:10:03 GMT
  6. Organization: Best Internet Communications
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <317326BE.246CF449@cantrip.org>
  9. References: <9604121530.AA08606@sun132.spd.dsccc.com> <316F646D.552DF1DD@cantrip.org> <KANZE.96Apr15210506@slsvgqt.lts.sel.alcatel.de>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset=us-ascii
  13. Content-Transfer-Encoding: 7bit
  14. X-Nntp-Posting-Host: ncm.vip.best.com
  15. X-Mailer: Mozilla 2.01 (X11; I; Linux 1.2.13 i386)
  16. Content-Length: 2343
  17. Originator: clamage@taumet
  18.  
  19. James Kanze US/ESC 60/3/141 #40763 wrote:
  20. > In article <316F646D.552DF1DD@cantrip.org> "Nathan Myers
  21. > <ncm@cantrip.org>" <ncm@cantrip.org> writes:
  22. > |> Bad things happen if you throw during copy construction or destruction
  23. > |> of a vector element.
  24.  
  25. > Does this imply that `vector< string >' is unsafe.  
  26.  
  27. That's debatable.  I think the Library WG expects that most
  28. implementations will guarantee that copying strings doesn't throw,
  29. though no such a guarantee is required by the standard.
  30.  
  31. It *does* imply that for `vector< deque<int> >', operations that
  32. require reallocation in the vector could trigger exceptions
  33. when copying the deque<int> container objects, leaving the vector 
  34. in an undefined state -- that is, it's not safe to call the 
  35. destructor.  For a vector on the stack, this would be pretty bad: 
  36. you would not be able to recover, or terminate the program normally.
  37.  
  38. > |> Don't let it happen.  (Yes, I know this is easier
  39. > |> said than done.  Still.)   There are lots of things in the library that
  40. > |> could break if a user object (or even a standard object!) throws during
  41. > |> a standard function. 
  42.  
  43. > If I understand what you are saying correctly, we should not use
  44. > exceptions with the standard library, because it will not be required
  45. > to be exception safe.  
  46.  
  47. I'm just talking about the current state of the Draft.  Yes, it 
  48. is as bad as it sounds, and will be until somebody figures out
  49. what to do about it and writes up a sound proposal.
  50.  
  51. Before you criticize this, consider what you would expect vector<> 
  52. to do when it is copying a block of elements from one memory region 
  53. to another, or deleting a block of elements, and an exception happens 
  54. in the middle.  Do you stop there, half-done?  Do you copy or delete
  55. the rest of the elements and leave a hole, then rethrow?  (What if you 
  56. get another exception while doing the rest?)
  57.  
  58. If you propagate the exception, member functions of the vector (including
  59. the destructor) will probably be called later.  What will they find?
  60.  
  61. This is a long way of asking: What do you mean by `required to be
  62. exception-safe'?  If you can define it, then probably the standard
  63. library ought to meet the definition.  If you *can't* define it,
  64. then (at least) you will then need to be careful about what you put 
  65. in a vector.  Pointers & PODs are OK. 
  66.  
  67. Nathan Myers
  68. ncm@cantrip.org
  69.  
  70.  
  71. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  72. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  73. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  74. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  75. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  76.